<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AI智能教学培训系统</title>
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
        }

        :root {
            --primary: #4361ee;
            --secondary: #3f37c9;
            --accent: #4895ef;
            --light: #f8f9fa;
            --dark: #212529;
            --success: #4cc9f0;
            --warning: #f72585;
            --gray: #6c757d;
        }

        body {
            background-color: #f5f7fb;
            color: var(--dark);
            overflow-x: hidden;
        }

        .app-container {
            display: flex;
            min-height: 100vh;
        }

        /* 侧边栏样式 */
        .sidebar {
            width: 260px;
            background: linear-gradient(180deg, var(--primary), var(--secondary));
            color: white;
            box-shadow: 3px 0 10px rgba(0, 0, 0, 0.1);
            transition: all 0.3s;
            z-index: 100;
            position: fixed;
            height: 100vh;
            overflow-y: auto;
        }

        .logo-container {
            padding: 20px;
            text-align: center;
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        }

        .logo {
            font-size: 24px;
            font-weight: 700;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .logo-icon {
            margin-right: 10px;
            font-size: 28px;
        }

        .nav-menu {
            padding: 20px 0;
        }

        .nav-item {
            padding: 12px 25px;
            display: flex;
            align-items: center;
            cursor: pointer;
            transition: all 0.3s;
            border-left: 4px solid transparent;
        }

        .nav-item:hover, .nav-item.active {
            background: rgba(255, 255, 255, 0.1);
            border-left: 4px solid var(--accent);
        }

        .nav-icon {
            margin-right: 12px;
            font-size: 18px;
        }

        /* 主内容区 */
        .main-content {
            flex: 1;
            margin-left: 260px;
            padding: 20px;
            transition: all 0.3s;
        }

        .header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 20px 0;
            margin-bottom: 20px;
            border-bottom: 1px solid #eaeaea;
        }

        .user-info {
            display: flex;
            align-items: center;
        }

        .avatar {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background: var(--accent);
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-weight: bold;
            margin-right: 10px;
        }

        .dashboard {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 20px;
            margin-bottom: 30px;
        }

        .card {
            background: white;
            border-radius: 12px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
            padding: 20px;
            transition: transform 0.3s;
        }

        .card:hover {
            transform: translateY(-5px);
        }

        .card-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 15px;
        }

        .card-title {
            font-size: 18px;
            font-weight: 600;
            color: var(--dark);
        }

        .progress-container {
            margin: 20px 0;
        }

        .progress-label {
            display: flex;
            justify-content: space-between;
            margin-bottom: 5px;
        }

        .progress-bar {
            height: 10px;
            background: #e9ecef;
            border-radius: 5px;
            overflow: hidden;
        }

        .progress-fill {
            height: 100%;
            background: var(--accent);
            border-radius: 5px;
        }

        .recommendation-item {
            display: flex;
            padding: 12px 0;
            border-bottom: 1px solid #eee;
        }

        .recommendation-item:last-child {
            border-bottom: none;
        }

        .rec-icon {
            width: 40px;
            height: 40px;
            background: rgba(67, 97, 238, 0.1);
            border-radius: 8px;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-right: 15px;
            color: var(--primary);
        }

        .rec-content {
            flex: 1;
        }

        .rec-title {
            font-weight: 600;
            margin-bottom: 5px;
        }

        .rec-desc {
            font-size: 13px;
            color: var(--gray);
        }

        .badge {
            padding: 4px 10px;
            border-radius: 20px;
            font-size: 12px;
            font-weight: 500;
        }

        .badge-primary {
            background: rgba(67, 97, 238, 0.1);
            color: var(--primary);
        }

        .badge-warning {
            background: rgba(247, 37, 133, 0.1);
            color: var(--warning);
        }

        .section-title {
            font-size: 20px;
            font-weight: 600;
            margin: 30px 0 20px;
            position: relative;
            padding-left: 15px;
        }

        .section-title:before {
            content: '';
            position: absolute;
            left: 0;
            top: 5px;
            height: 20px;
            width: 5px;
            background: var(--primary);
            border-radius: 3px;
        }

        .courses-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
            gap: 20px;
        }

        .course-card {
            background: white;
            border-radius: 12px;
            overflow: hidden;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
            transition: all 0.3s;
        }

        .course-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
        }

        .course-image {
            height: 160px;
            background: var(--primary);
            position: relative;
        }

        .course-tag {
            position: absolute;
            top: 15px;
            right: 15px;
            background: var(--warning);
            color: white;
            padding: 4px 10px;
            border-radius: 4px;
            font-size: 12px;
            font-weight: 500;
        }

        .course-content {
            padding: 20px;
        }

        .course-title {
            font-size: 18px;
            font-weight: 600;
            margin-bottom: 10px;
        }

        .course-stats {
            display: flex;
            justify-content: space-between;
            color: var(--gray);
            font-size: 14px;
            margin-top: 15px;
        }

        .chat-container {
            background: white;
            border-radius: 12px;
            overflow: hidden;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
        }

        .chat-header {
            padding: 20px;
            background: var(--primary);
            color: white;
            font-weight: 600;
        }

        .chat-messages {
            height: 300px;
            padding: 20px;
            overflow-y: auto;
            background: #fafafa;
        }

        .message {
            margin-bottom: 20px;
            display: flex;
        }

        .message.bot .message-content {
            background: white;
            border: 1px solid #eee;
            border-radius: 0 15px 15px 15px;
        }

        .message.user {
            justify-content: flex-end;
        }

        .message.user .message-content {
            background: var(--accent);
            color: white;
            border-radius: 15px 0 15px 15px;
        }

        .message-content {
            max-width: 70%;
            padding: 12px 16px;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
        }

        .chat-input {
            display: flex;
            padding: 15px;
            background: white;
            border-top: 1px solid #eee;
        }

        .chat-input input {
            flex: 1;
            padding: 12px 15px;
            border: 1px solid #ddd;
            border-radius: 25px;
            outline: none;
            transition: all 0.3s;
        }

        .chat-input input:focus {
            border-color: var(--accent);
            box-shadow: 0 0 0 2px rgba(67, 97, 238, 0.2);
        }

        .chat-input button {
            margin-left: 10px;
            background: var(--primary);
            color: white;
            border: none;
            border-radius: 25px;
            padding: 10px 20px;
            cursor: pointer;
            transition: all 0.3s;
        }

        .chat-input button:hover {
            background: var(--secondary);
        }

        .toggle-role {
            margin-top: 20px;
            text-align: center;
        }

        .toggle-btn {
            background: var(--accent);
            color: white;
            border: none;
            padding: 8px 20px;
            border-radius: 20px;
            cursor: pointer;
            font-weight: 500;
            transition: all 0.3s;
        }

        .toggle-btn:hover {
            background: var(--secondary);
        }

        /* 教师面板特定样式 */
        .teacher-view .card {
            background: white;
        }

        .stats-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
            gap: 20px;
            margin-bottom: 30px;
        }

        .stat-card {
            background: white;
            border-radius: 12px;
            padding: 20px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
            text-align: center;
        }

        .stat-value {
            font-size: 32px;
            font-weight: 700;
            color: var(--primary);
            margin: 10px 0;
        }

        .stat-label {
            color: var(--gray);
            font-size: 14px;
        }

        /* 响应式设计 */
        @media (max-width: 992px) {
            .sidebar {
                width: 70px;
            }

            .logo-text, .nav-text {
                display: none;
            }

            .logo-icon {
                margin-right: 0;
            }

            .nav-item {
                justify-content: center;
            }

            .nav-icon {
                margin-right: 0;
            }

            .main-content {
                margin-left: 70px;
            }
        }

        @media (max-width: 768px) {
            .dashboard {
                grid-template-columns: 1fr;
            }

            .courses-grid {
                grid-template-columns: 1fr;
            }
        }

        /* 动画效果 */
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(10px); }
            to { opacity: 1; transform: translateY(0); }
        }

        .fade-in {
            animation: fadeIn 0.5s ease forwards;
        }

        /* 侧边栏链接无下划线且不变色 */
        a.nav-item {
            text-decoration: none;
            color: inherit;
        }
        a.nav-item:visited,
        a.nav-item:active,
        a.nav-item:focus {
            color: inherit;
        }
    </style>
</head>
<body>
<div id="app">
    <div class="app-container">
        <!-- 侧边导航 -->
        <div id="sidebar"></div>

        <!-- 主内容区 -->
        <div class="main-content" :class="{'teacher-view': isTeacherView}">
            <!-- 顶部导航 -->
            <div class="header">
                <h1>{{ isTeacherView ? '教师管理面板' : '学习中心' }}</h1>
                <div class="user-info">
                    <div class="avatar">{{ userInitials }}</div>
                    <div>
                        <div class="user-name">{{ currentUser.name }}</div>
                        <div class="user-role">{{ isTeacherView ? '教师' : '学生' }}</div>
                    </div>
                </div>
            </div>

            <!-- 学生视图 -->
            <div v-if="!isTeacherView">
                <!-- 数据卡片 -->
                <div class="dashboard">
                    <div class="card fade-in">
                        <div class="card-header">
                            <div class="card-title">学习课程</div>
                            <div class="badge badge-primary">100%</div>
                        </div>
                        <div class="progress-container">
                            <div class="progress-label">
                                <span>学习门数</span>
                                <span>8</span>
                            </div>
                            <div class="progress-bar">
                                <div class="progress-fill" style="width: 100%"></div>
                            </div>
                        </div>
                    </div>

                    <div class="card fade-in">
                        <div class="card-header">
                            <div class="card-title">完成作业</div>
                            <div class="badge badge-warning">16项</div>
                        </div>
                        <div>
                            <div class="recommendation-item">
                                <div class="rec-icon">
                                    <i class="el-icon-s-claim"></i>
                                </div>
                                <div class="rec-content">
                                    <div class="rec-title">高等数学 - 单元测试</div>
                                </div>
                            </div>
                            <div class="recommendation-item">
                                <div class="rec-icon">
                                    <i class="el-icon-video-camera"></i>
                                </div>
                                <div class="rec-content">
                                    <div class="rec-title">线性代数 - 第5讲</div>
                                </div>
                            </div>
                            <div class="recommendation-item">
                                <div class="rec-icon">
                                    <i class="el-icon-document"></i>
                                </div>
                                <div class="rec-content">
                                    <div class="rec-title">数据库 - 单元测试</div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="card fade-in">
                        <div class="card-header">
                            <div class="card-title">完成考试数量</div>
                            <i class="el-icon-s-opportunity" style="color: var(--accent)"></i>
                        </div>
                        <div>
                            <div class="recommendation-item">
                                <div class="rec-icon">
                                    <i class="el-icon-reading"></i>
                                </div>
                                <div class="rec-content">
                                    <div class="rec-title">线性代数期末考试</div>
                                    <div class="rec-desc">未及格，需重新考试</div>
                                </div>
                            </div>
                            <div class="recommendation-item">
                                <div class="rec-icon">
                                    <i class="el-icon-s-order"></i>
                                </div>
                                <div class="rec-content">
                                    <div class="rec-title">操作系统原理期末考试</div>
                                    <div class="rec-desc">未及格，需重新考试</div>
                                </div>
                            </div>
                            <div class="recommendation-item">
                                <div class="rec-icon">
                                    <i class="el-icon-video-camera"></i>
                                </div>
                                <div class="rec-content">
                                    <div class="rec-title">数据库系统概论单元测试</div>
                                    <div class="rec-desc">基础非常差，请继续努力</div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- 推荐资源展示区（美化版） -->
                <div class="card" style="margin-top: 20px; margin-bottom: 0; box-shadow: 0 6px 24px rgba(67,97,238,0.08);">
                    <div class="card-header" style="border-bottom:1px solid #f0f0f0;">
                        <span class="card-title" style="color:#4361ee;font-size:20px;letter-spacing:1px;">为你推荐的学习资源</span>
                    </div>
                    <div id="recommend-resource-list">
                        <div v-if="recommendResources.length === 0" style="color:#888; padding:32px 0; text-align:center;">暂无推荐资源</div>
                        <div v-for="(res, idx) in recommendResources" :key="res.resource_id" class="recommendation-item"
                            style="display:flex;align-items:flex-start;padding:22px 0;transition:background 0.2s; border-bottom:1px solid #f3f3f3;"
                            :style="{background: hoverIdx===idx ? '#f8faff' : 'white'}"
                            @mouseenter="hoverIdx=idx" @mouseleave="hoverIdx=-1">
                            <div class="rec-icon" style="margin-right:20px;display:flex;align-items:center;justify-content:center;width:48px;height:48px;background:linear-gradient(135deg,#e3eafe,#f8faff);border-radius:12px;">
                                <i class="el-icon-notebook-2" style="font-size:28px;color:#4361ee;"></i>
                            </div>
                            <div style="flex:1;min-width:0;">
                                <div style="font-weight:700;font-size:17px;color:#222;line-height:1.4;word-break:break-all;white-space:normal;">{{ res.title }}</div>
                                <div style="color:#666;font-size:13px;margin:8px 0 6px 0;line-height:1.6;word-break:break-all;white-space:normal;">{{ res.description }}</div>
                            </div>
                            <div style="margin-left:24px;text-align:right;min-width:90px;">
                                <div style="font-size:13px;color:#4361ee;font-weight:600;">使用次数 <span style="color:#4361ee;font-weight:600;">{{ res.use_number }}</span></div>
                                <div style="font-size:13px;color:#f72585;font-weight:700;">推荐分 <span style="color:#f72585;font-weight:700;">{{ res.final_score.toFixed(2) }}</span></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    new Vue({
        el: '#app',
        data: {
            isTeacherView: false,
            currentUser: {
                name: '张明',
                role: 'student'
            },
            courses: [], // 改为由API获取
            students: [
                { name: '李明', progress: 85, lastActive: '今天 09:45', trend: 'up' },
                { name: '王芳', progress: 92, lastActive: '今天 08:30', trend: 'up' },
                { name: '张伟', progress: 65, lastActive: '昨天 22:15', trend: 'up' },
                { name: '刘洋', progress: 78, lastActive: '今天 10:20', trend: 'down' },
                { name: '陈晓', progress: 45, lastActive: '昨天 19:40', trend: 'down' }
            ],
            recommendResources: [],
            hoverIdx: -1
        },
        mounted() {
            // 获取用户信息
            fetch('/user/profile', {
                headers: {
                    'Authorization': 'Bearer ' + localStorage.getItem('token')
                }
            })
            .then(res => res.json())
            .then(resp => {
                if (resp.success && resp.data) {
                    this.currentUser = resp.data;
                } else {
                    console.error('获取用户信息失败:', resp.message);
                }
            })
            .catch(error => {
                console.error('请求用户信息出错:', error);
            });

            // 获取课程数据
            fetch('/courses', {
                headers: {
                    'Authorization': 'Bearer ' + localStorage.getItem('token')
                }
            })
            .then(res => res.json())
            .then(resp => {
                if (resp.success && Array.isArray(resp.data)) {
                    this.courses = resp.data;
                } else {
                    console.error('获取课程数据失败:', resp.message);
                    this.courses = [];
                }
            })
            .catch(error => {
                console.error('请求课程数据出错:', error);
                this.courses = [];
            });

            // 获取推荐资源数据
            fetch('recommend_result.json')
                .then(res => res.json())
                .then(data => {
                    this.recommendResources = data;
                })
                .catch(() => {
                    this.recommendResources = [];
                });
        },
        computed: {
            userInitials() {
                return this.currentUser.name.substring(0, 1);
            }
        },
        methods: {
            toggleRole() {
                this.isTeacherView = !this.isTeacherView;
                this.currentUser.name = this.isTeacherView ? '王教授' : '张明';
            }
        }
    });
</script>
<script>
  fetch('sidebar.html').then(r=>r.text()).then(html=>{document.getElementById('sidebar').innerHTML=html;});
</script>

</body>
</html>